#coding=utf-8
from django.contrib.auth.models import User, Group
from django.db import models
from DjangoUeditor.models import UEditorField
from PublicTool.BaseModel import Base_UserModel


class VisitPerm(Base_UserModel):
    PERM_YES=1
    PERM_NO=0
    PERM_ALLOW=(
        (PERM_YES, '允许'),
        (PERM_NO, '禁止'),
    )

    name=models.CharField(u"权限说明",max_length=100)

    needMoney=models.IntegerField(u"需要金钱",blank=True,null=True)
    needExpr=models.IntegerField(u"需要经验",blank=True,null=True)

    question=models.CharField(u"访问提问",max_length=20,blank=True,null=True)
    answer=models.CharField(u"答案",max_length=10,blank=True,null=True)

    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '权限'
        verbose_name_plural = '权限'
        abstract = True


class VisitPermClass(VisitPerm):
    allowUsers=models.ManyToManyField(User,verbose_name=u"允许用户",blank=True,null=True,related_name='allowUsers')
    allowRoles=models.ManyToManyField(Group,verbose_name=u"允许角色",blank=True,null=True,related_name='allowRoles')
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '板块权限'
        verbose_name_plural = '板块权限'
class VisitPermTheme(VisitPerm):
    spendMoney=models.IntegerField(u"花费金钱",blank=True,null=True)
    replyVisible=models.BooleanField(u"回复可见",default=False)
    allowReply=models.BooleanField(u"允许发表评论",default=True)
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '主题权限'
        verbose_name_plural = '主题权限'


class SystemLog(Base_UserModel):
    TYPE_ADD=0
    TYPE_DELETE=1
    TYPE_UPDATE=2
    TYPE_SELECT=(
        (TYPE_ADD,u'添加'),
        (TYPE_DELETE,u'删除'),
        (TYPE_UPDATE,u'编辑'),
    )

    moduleName=models.CharField(u"模块名称",max_length=10)
    typeName=models.PositiveSmallIntegerField(u"操作类型",choices=TYPE_SELECT,default=TYPE_UPDATE)
    remark=models.CharField(u"操作说明",max_length=100,null=True,blank=True)
    outId=models.IntegerField(u'相关外键',null=True,blank=True)
    ip=models.IPAddressField(u'IP地址',null=True,blank=True)

    def __unicode__(self):
        return self.remark
    class Meta:
        verbose_name = '系统日志'
        verbose_name_plural = '系统日志'

class Report(Base_UserModel):
    url=models.CharField(u'网址',max_length=100)
    classId=models.ForeignKey('BbsTheme.BbsClass',verbose_name=u'板块',null=True,blank=True)
    content=UEditorField(u'违规内容',height=200,width=600,imagePath="HelpReport",imageManagerPath="HelpReport",filePath="HelpReport",blank=True,null=True)
    def __unicode__(self):
        return self.url
    class Meta:
        verbose_name = '举报'
        verbose_name_plural = '举报'